package com.chudian.controller;

import com.chudian.entity.OrderInfo;
import com.chudian.enums.OrderStatus;
import com.chudian.service.OrderInfoService;
import com.chudian.vo.R;
import com.mysql.cj.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : ZhangCheng
 * @date Date : 2022年10月27日
 */
@CrossOrigin //跨域
@Api(tags="订单管理") //用在类上
@RestController
@RequestMapping("/api/order-info")
@Slf4j
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @GetMapping("/list")
    @ApiOperation("获取订单列表")
    public R list(){
        List<OrderInfo> list=orderInfoService.getOrderInfoByCreatetimeDesc();
        return R.ok().data("list", list);
    }

    /**
     * 查询本地订单状态
     * @param orderNo
     * @return
     */
    @ApiOperation("查询订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){

        log.info("查询本地订单状态！");

        String orderState = orderInfoService.getOrderState(orderNo);
        if(OrderStatus.SUCCESS.getType().equals(orderState)){
            return R.ok().setMessage("支付成功");  //支付成功
        }
        return R.ok().setCode(101).setMessage("支付中......");
    }
}
